package com.yeyaomai.dksns.flowis.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import com.yeyaomai.dksns.flowis.dao.FeedbackDao;
import com.yeyaomai.dksns.flowis.domain.Feedback;
import com.yeyaomai.dksns.flowis.domain.flowisdetail.FlowisQueryOrder;
import com.yeyaomai.dksns.flowis.page.PageImplResult;
import com.yeyaomai.dksns.flowis.page.PageRequestOrder;
import com.yeyaomai.dksns.flowis.page.SplitConstant;
import com.yeyaomai.dksns.flowis.service.FeedbackService;

@Service
public class FeedbackServiceimpl implements FeedbackService {

	@Resource
	private FeedbackDao feedbackDao;

	@Override
	public void addFeedback(Feedback feedback) {
		feedback.setCreateTime(new Date());
		feedbackDao.addFeedback(feedback);

	}

	@Override
	public Page<Feedback> getSplit(FlowisQueryOrder order) {
		
		PageRequestOrder page = new PageRequestOrder(Integer.valueOf(order.getNumber()) , SplitConstant.PAGE_SIZE);
		long countFeedback = feedbackDao.countFeedback();
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		map.put("startNumber", page.start()); 
		map.put("pageSize", SplitConstant.PAGE_SIZE); 
		List<Feedback> accessList = feedbackDao.getFeedback(map);
		Page<Feedback> result = new PageImplResult<Feedback>(accessList, page, countFeedback);
		return result;
	}

	@Override
	public Feedback getFeedbackById(long id) {
		return feedbackDao.getFeedbackById(id);
	}
}
